#!/bin/sh
killall dhcpd3

echo >&2 new_bt_devup.sh $1 $2
INTERNAL=$1
#EXTERNAL=`cat ./lib/EXTERNAL.txt`
#echo >&2 ETXERNAL=$EXTERNAL
echo >&2  ""

if test $1 = bnep0
then 
	IP=192.168.0.1
	INTERFACES='bnep0'
fi

if test $1 = bnep1
then 
	IP=192.168.1.1
	INTERFACES='bnep0 bnep1'
fi

if test $1 = bnep2
then 
	IP=192.168.2.1
	INTERFACES='bnep0 bnep1 bnep2'
fi

if test $1 = bnep3
then 
	IP=192.168.3.1
	INTERFACES='bnep0 bnep1 bnep2 bep3'
fi

echo >&2 IP=$IP
echo >&2  ""

>&2 ifconfig $1 

# setting the new local interface ip address
echo  >&2 ifconfig $INTERNAL $IP
ifconfig $INTERNAL $IP
echo  >&2 ""

 >&2 ifconfig $1

#starting routing between the new interface to the Internet

#echo 1 > /proc/sys/net/ipv4/ip_forward
#iptables -t nat -A POSTROUTING -s `echo $IP`/24 -o $EXTERNAL -j MASQUERADE
#iptables -A FORWARD -i $INTERNAL -o $EXTERNAL -j ACCEPT
#iptables -A FORWARD -o $INTERNAL -i $EXTERNAL -j ACCEPT

#iptables -A INPUT -i $INTERNAL -j ACCEPT
#iptables -A INPUT -i $EXTERNAL -j ACCEPT

#iptables -A OUTPUT -o $INTERNAL -j ACCEPT
#iptables -A OUTPUT -o $EXTERNAL -j ACCEPT


>&2 ifconfig $1

# setting the new local interface ip address
echo ifconfig $INTERNAL $IP
ifconfig $INTERNAL $IP
echo  >&2 ""

>&2 ifconfig $1

# starting dhcp server on the new interface
#echo  >&2 dhcpd3 $INTERNAL -cf ./lib/my_dhcpd3_Bluetooth_`echo $1`.conf -f -d
echo  >&2 dhcpd3 $INTERFACES -cf ./lib/my_dhcpd3_Bluetooth.conf -f -d
ifconfig $INTERNAL $IP
#dhcpd3 $INTERNAL -cf ./lib/my_dhcpd3_Bluetooth_`echo $1`.conf -f -d
dhcpd3 $INTERFACES -cf ./lib/my_dhcpd3_Bluetooth.conf -f -d

>&2 ifconfig $1
